<?php


namespace app\common\cachemodel\zlcr2;


use app\common\model\BaseCache;

class Zlcr2UserQuestionComment extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.zlcr2_user_question_comment';

    protected $cacheModel = 'question_answer.question_comment';


    /**
     * 重写数据时获取数据
     * @param $ids
     * @param $type
     * @param $sortType
     * @return array|false|string
     */
    public function getInfoByIdsInData($ids, $type, $sortType)
    {
        try
        {
            $data = $this->alias('c')->where('c.qid', 'in', $ids)->join('wechat_backup_07_18_14_43_00.zlcr_tag t', 'c.tid=t.id')
                ->column('c.level,c.tid,c.comment,c.astr_id,c.comment_type,c.create_time,t.tag_name,t.tag_type,t.score,t.flag', 'c.qid');
        }
        catch (\Exception $e)
        {
            $data = [];
        }

        return $data;
    }

    public function batchGetInfoByIds($cids, $field = [])
    {
        $resData = parent::batchGetInfoByIds($cids, $field);

        foreach ($resData as $orderId => $orderItemData)
        {
            $resData[$orderId] = arrayKeyData2int($orderItemData, ['level', 'tid', 'astr_id', 'comment_type', 'create_time', 'tag_type', 'score', 'flag']);
        }

        return $resData;
    }


    /**
     * 获取单条数据缓存
     * @param $cid
     * @param array $field
     * @return mixed
     * @throws \Exception
     */
    public function getInfoById($cid, $field = [])
    {
        $data = $this->batchGetInfoByIds($cid, $field);

        return current($data);
    }
}
